/**
 * @Title: modal1.js
 * @Description: modal0
 * @author: Fanchao
 * @date: 2021/2/5 2:03 下午
 * @version V1.0
 */
import React from 'react';
import { connect } from 'umi';
import { Form, InputNumber, Modal } from 'antd';

const layout = {
    labelCol: { span: 6 },
    wrapperCol: { span: 18 },
};
const Modal1 = ({ computeScheme: { tab1Show, item1Data }, dispatch }) => {
    const [form] = Form.useForm();
    form.setFieldsValue({
        minStudentSample: item1Data.minStudentSample,
        maxStudentSample: item1Data.maxStudentSample,
        studentWeight: item1Data.studentWeight,
        schoolExpertWeight: item1Data.schoolExpertWeight,
        centerWeight: item1Data.centerWeight,
        teachSectionWeight: item1Data.teachSectionWeight,
    });
    return (
        <Modal
            title={'添加/修改四位权重方案'}
            visible={tab1Show}
            width="800px"
            onOk={() => {
                form.validateFields().then(values => {
                    if (item1Data.resultWeightPlanId) {
                        values.resultWeightPlanId = item1Data.resultWeightPlanId;
                        dispatch({
                            type: 'computeScheme/updateTab1Item',
                            payload: values,
                            callback: (result) => {
                                if (result) {
                                    form.resetFields();
                                    dispatch({
                                        type: 'computeScheme/setItem1Data',
                                        payload: {},
                                    });
                                    dispatch({
                                        type: 'computeScheme/setTab1Show',
                                        payload: false,
                                    });
                                    dispatch({
                                        type: 'computeScheme/getTab1List',
                                    });
                                }
                            },
                        });
                    } else {
                        dispatch({
                            type: 'computeScheme/addTab1Item',
                            payload: values,
                            callback: (result) => {
                                if (result) {
                                    form.resetFields();
                                    dispatch({
                                        type: 'computeScheme/setItem1Data',
                                        payload: {},
                                    });
                                    dispatch({
                                        type: 'computeScheme/setTab1Show',
                                        payload: false,
                                    });
                                    dispatch({
                                        type: 'computeScheme/getTab1List',
                                    });
                                }
                            },
                        });
                    }
                }).catch(info => {
                });
            }}
            onCancel={() => {
                form.resetFields();
                dispatch({
                    type: 'computeScheme/setItem1Data',
                    payload: {},
                });
                dispatch({
                    type: 'computeScheme/setTab1Show',
                    payload: false,
                });
            }}
        >
            <Form
                {...layout}
                layout="horizontal"
                form={form}
                name="basic"
                // 表单默认值，只有初始化以及重置时生效 莫用
                initialValues={{
                    // name: item1Data.name
                }}
            >
                <Form.Item
                    label="最小学员样本数（不包含）"
                    name="minStudentSample"
                    rules={[{ required: true, message: '必填' }]}
                >
                    <InputNumber
                        min={0}
                        formatter={value => `${value}`}
                        parser={value => parseInt(value ? value : 0)}
                        style={{ width: '100%' }}
                        placeholder="请输入最小学员样本数"
                    />
                </Form.Item>
                <Form.Item
                    label="最大学员样本数（包含）"
                    name="maxStudentSample"
                    rules={[{ required: false, message: '必填' }]}
                >
                    <InputNumber
                        min={1}
                        formatter={value => `${value}`}
                        parser={value => value > 0 ? parseInt(value ? value : 0) : ''}
                        style={{ width: '100%' }}
                        placeholder="请输入最大学员样本数"
                    />
                </Form.Item>
                <Form.Item
                    label="学员评分权重"
                    name="studentWeight"
                    rules={[{ required: true, message: '必填' }]}
                >
                    <InputNumber
                        min={0}
                        max={99}
                        step={0.1}
                        formatter={value => `${value}%`}
                        parser={value => value.replace('%', '')}
                        style={{ width: '100%' }}
                        placeholder="请输入学员评分权重"
                    />
                </Form.Item>
                <Form.Item
                    label="校专家评分权重"
                    name="schoolExpertWeight"
                    rules={[{ required: true, message: '必填' }]}
                >
                    <InputNumber
                        min={0}
                        max={99}
                        step={0.1}
                        formatter={value => `${value}%`}
                        parser={value => value.replace('%', '')}
                        style={{ width: '100%' }}
                        placeholder="请输入校专家评分权重"
                    />
                </Form.Item>
                <Form.Item
                    label="部系评分权重"
                    name="centerWeight"
                    rules={[{ required: true, message: '必填' }]}
                >
                    <InputNumber
                        min={0.1}
                        max={99}
                        step={0.1}
                        formatter={value => `${value}%`}
                        parser={value => value.replace('%', '')}
                        style={{ width: '100%' }}
                        placeholder="请输入部系评分权重"
                    />
                </Form.Item>
                <Form.Item
                    label="教研室评分权重"
                    name="teachSectionWeight"
                    rules={[{ required: true, message: '必填' }]}
                >
                    <InputNumber
                        min={0.1}
                        max={99}
                        step={0.1}
                        formatter={value => `${value}%`}
                        parser={value => value.replace('%', '')}
                        style={{ width: '100%' }}
                        placeholder="请输入教研室评分权重"
                    />
                </Form.Item>
            </Form>
        </Modal>
    );
};


export default connect(({ computeScheme, dispatch }) => ({
    computeScheme,
    dispatch,
}))(Modal1);
